Repository navigation
fix: let nested keys override non-mapping values in build_dict (#215) - #224
Open
patchwright wants to merge 1 commit into
Open
patchwright wants to merge 1 commit into
patchwright wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #215. A nested key that overrides a non-mapping value inside an existing mapping raises. With
APP_DATABASE="{host: localhost, port: 5432}"andAPP_DATABASE__PORT=5433,EnvSource("APP_", parse_yaml_docs=True)fails withAttributeError: 'int' object has no attribute 'update'.set_args({'database': {'port': 5432}, 'database.port': 5433}, dots=True)hits the same path. Confirmed on main HEAD 23bc86a.Root cause
build_dictinconfuse/util.pycallssave_to[key].update(result)wheneverkeyalready exists, even if the existing value is a scalar, list or None.Fix
Only call
.update()when both the existing value and the new result are dicts. Otherwise the new, more specific value replaces the old one. Mapping-to-mapping shallow merges behave as before. One line changed inutil.py, plus tests and a changelog entry.How to test
The three new tests fail on current main (AttributeError) and pass with this change. Full suite: 308 passed, 1 skipped (
test_release.py, needsclick).Backward compatibility
No API changes. Inputs that used to raise now return the more specific value.
Assisted-by: Claude (code generation, reviewed and tested locally)